package com.furns.web;

import com.furns.entity.Manager;
import com.furns.service.ManagerService;
import com.furns.service.impl.ManagerServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author LuoJiaCheng
 * @ID 2240129126
 * @Version 1.0
 */
@WebServlet(name = "AdminServlet", value = "/AdminServlet")
public class AdminServlet extends BasicServlet{

    private ManagerService managerService = new ManagerServiceImpl();

    protected void manageLogin (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String user_name = req.getParameter("user-name");
        String user_password = req.getParameter("user-password");
        Manager manager = managerService.login(new Manager(null, user_name, user_password));
        if(manager!=null){
            req.getSession().setAttribute("manager",manager);
            req.getRequestDispatcher("/views/manage/manage_menu.jsp").forward(req,resp);
        }else{
            req.setAttribute("error","管理员账号或密码输入错误");
            req.getRequestDispatcher("/views/manage/manage_login.jsp").forward(req,resp);
        }
    }
}
